import {reqCateList,reqList,reqGoodsByCateIdAndSubId} from '@/api'
export default {
    state: {
        cateInfo: {},
        listInfo: {},
        goodsInfo: {}
    },
    mutations: {
        //设置分类信息
        SET_CATELIST(state,cateInfo) { 
            state.cateInfo=cateInfo
        },
        SET_LIST(state, listInfo) {
            state.listInfo=listInfo
        },
        SET_GOODS_INFO(state, info) {
            state.goodsInfo = info
         }
    },
    actions: {
        //获取分类数据
        async getCateList({ commit,dispatch,state},cateId="") { 
            let res = await reqCateList(cateId)
            commit('SET_CATELIST',res.data)
        },

        //根据cateid获取商品列表
        async getGoodsByCateId({ commit, dispatch }, id) { 
            let res = await reqList(id)
            // console.log(res);
            commit('SET_LIST',res.data);
        },

        //商品列表
        async getGoodsByCateIdAndBySubId({ commit }, { categoryId, subCategoryId }) { 
            let res = await reqGoodsByCateIdAndSubId(categoryId, subCategoryId)
            commit('SET_GOODS_INFO',res.data)
            // console.log(res);
        }

    },
    getters: {
       
        categoryItemList(state) { 
            return state.listInfo.categoryItemList || []
        },
        
        categoryItems(state) { 
            return state.goodsInfo.categoryItems || {}
        },
        categoryL2List2(state) { 
            return state.goodsInfo.categoryL2List || []
        },
        categoryL1List1(state) { 
            return state.cateInfo.categoryL1List || []
        },
        currentCategory1(state) { 
            return state.listInfo.currentCategory || {}
        },

    }
}